package ${package.Controller};


import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import ${package.Parent}.dto.${entity}DTO;
import ${package.Parent}.dto.${entity}PageDTO;
import ${package.Parent}.service.I${entity}Service;
import ${package.Parent}.vo.${entity}PageVO;
import ${package.Parent}.vo.${entity}VO;
import com.hz.common.model.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

<#--<#if restControllerStyle>-->
import org.springframework.web.bind.annotation.RestController;
<#--<#else>
import org.springframework.stereotype.Controller;
</#if>-->
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 * ${table.comment!} 前端控制器
 *
 * @author ${author} created on ${date}
 */
<#--
<#if restControllerStyle>
-->
@RestController
<#--<#else>
@Controller
</#if>-->
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
@Api("${table.comment!}")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>

    @Autowired
    private I${entity}Service ${entity?uncap_first}Service;

    @PostMapping("/add")
    @ApiOperation(value = "添加", notes = "添加")
    public Result<Boolean> add(@Validated @RequestBody ${entity}DTO ${entity?uncap_first}DTO) {
        return success(${entity?uncap_first}Service.add(${entity?uncap_first}DTO));
    }

    @PostMapping("/page")
    @ApiOperation(value = "分页查询", notes = "分页查询")
    public Result<Page<${entity}PageVO>> page(@RequestBody ${entity}PageDTO ${entity?uncap_first}PageDTO) {
        return success(${entity?uncap_first}Service.getPagesByCondition(getPage(), ${entity?uncap_first}PageDTO));
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除", notes = "删除")
    public Result<Boolean> delete(@RequestParam("id") Integer id) {
        return success(${entity?uncap_first}Service.deleteBy${entity}Id(id));
    }

    @GetMapping("/detail")
    @ApiOperation(value = "查看详情", notes = "查看详情")
    public Result<${entity}VO> detail(@RequestParam("id") Integer id) {
        return success(${entity?uncap_first}Service.detail(id));
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改", notes = "修改")
    public Result<Boolean> update(@Validated @RequestBody ${entity}DTO ${entity?uncap_first}DTO) {
        return success(${entity?uncap_first}Service.updateBy${entity}Id(${entity?uncap_first}DTO));
    }

}
</#if>
